#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <iostream>
#include <string>

int main()
{
#if 0
   unsigned int inputNum = 0;
   std::cout << "please input a number:";
   std::cin >> inputNum;
   std::cout << "你输入的数字为：" << inputNum << std::endl;
   std::string strTmp;
   int strLen = 0;
   for (int i = 0; i < 8; ++i) {
       if (inputNum != 0) {
           strTmp.push_back((inputNum & 0xf) + '0');
           inputNum >>= 4;
           ++strLen;
       }
       else {
           break;
       }
   } 
   strTmp.insert(strTmp.begin(), strLen);
   
   std::cout << "转成字符串：" << strTmp << std::endl;
   std::cout << "字符串长度：" << strTmp.length() << std::endl;
   std::cout << "字符长度：" << (int)strTmp[0] << std::endl;
   int lenth = strTmp[0];
   unsigned int numTmp = 0;
   for (int i = lenth; i > 0; --i) {
       char dt = strTmp[i];
       if (0 != dt) {
           numTmp <<= 4;
           numTmp |= dt - '0';
       }
   }
   std::cout << "再转回数字为：" << numTmp << std::endl;
#else
   unsigned int inputNum = 0;
   std::cout << "please input a number:";
   std::cin >> inputNum;
   std::cout << "你输入的数字为：" << inputNum << std::endl;
   std::string strTmp;
   while (0 != inputNum) {
       strTmp.insert(strTmp.begin(), (inputNum % 10) + '0');
       inputNum /= 10;
   }

   std::cout << "转成字符串：" << strTmp << std::endl;
   std::cout << "字符串长度：" << strTmp.length() << std::endl;
   unsigned int numTmp = 0;
   for (int i = 0; i < strTmp.length(); ++i) {
       numTmp *= 10;
       numTmp += strTmp[i] - '0';
   }
   std::cout << "再转回数字为：" << numTmp << std::endl;
#endif
   return 0;
}
